package org.javaboy.vhr.controller.emp;

import org.javaboy.vhr.mapper.EmpSalaryMapper;
import org.javaboy.vhr.model.EmpSalary;
import org.javaboy.vhr.model.Employee;
import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.model.Salary;
import org.javaboy.vhr.service.EmpSalrayService;
import org.javaboy.vhr.service.EmployeeecService;
import org.javaboy.vhr.vo.RespBean;
import org.javaboy.vhr.vo.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/employee/empSalary")
public class EmpSalaryController {
    @Autowired
    EmpSalrayService empSalrayService;
    @GetMapping("/")
    public RespPageBean getEmployeeecByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, EmpSalary empSalary, Date[] beginDateScope) {
        return empSalrayService.getEmployeeSalaryByPage(page,size,empSalary,beginDateScope);
    }

    @GetMapping("/getTotalSalary")
    public RespBean getTotalSalary(){
        List<Salary> salaries = empSalrayService.getTotalSalary();
        //就因为ok这个静态方法，导致返回的是一个RespBean对象！前端接受的是一个对象！
        if(salaries != null) {
            return  RespBean.ok("操作成功",salaries);
        }else
            return RespBean.error("操作失败");
    }

    @PostMapping("/add")
    public RespBean addEmpSalary(@RequestBody EmpSalary empSalary){
        int result = empSalrayService.add(empSalary);
        if(result != 1) return  RespBean.error("添加失败");
        else return RespBean.ok("添加成功");
    }

    @PutMapping("/update")
    public RespBean updateEmpSalary(@RequestBody EmpSalary empSalary){
        int result = empSalrayService.updateEmpSalary(empSalary);
        if(result != 1) return  RespBean.error("更新失败");
        else return RespBean.ok("更新成功");
    }

    @DeleteMapping("/delete/{id}")
    public RespBean DeleteEmpSalary(@PathVariable(value = "id") Integer id){
        int result = empSalrayService.deleteEmpSalary(id);
        if(result != 1) return  RespBean.error("删除失败");
        else return RespBean.ok("删除成功");
    }


}
